﻿using System.Xml.Linq;

namespace Bing
{
    /// <summary>
    /// Represents a results returned from an <see cref="InstantAnswerResponse"/> where the <see cref="InstantAnswerResult.ContentType"/> was Encarta.
    /// </summary>
    public class Encarta
    {
        /// <summary>
        /// Gets or sets the indicator.
        /// </summary>
        /// <value>The indicator.</value>
        public string Indicator { get; set; }
        /// <summary>
        /// Gets or sets the year.
        /// </summary>
        /// <value>The year.</value>
        public string Year { get; set; }
        /// <summary>
        /// Gets or sets the value.
        /// </summary>
        /// <value>The value.</value>
        public string Value { get; set; }

        /// <summary>
        /// Parses the <c>Encarta</c>.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        public static Encarta ParseEncarta(XNode element)
        {
            Encarta encarta = new Encarta();

            encarta.Indicator = ApiHelper.GetElementValueOrDefault<string>(element, "Indicator", ApiHelper.EncartaNs);
            encarta.Year = ApiHelper.GetElementValueOrDefault<string>(element, "Year", ApiHelper.EncartaNs);
            encarta.Value = ApiHelper.GetElementValueOrDefault<string>(element, "Value", ApiHelper.EncartaNs);

            return encarta;
        }
    }
}
